from browser . logic import browser_logic

class mediator_fake :
    def __init__ ( self ) :
        self . _browser_logic = None
        self . _knowledge_bases_fetched = None
        self . _knowledge_base_receiving_callback = None
        self . _all_knowledge_bases = [ ]
        self . _entry_text = None
        self . _renamed_bases = [ ]
        self . _call_history = [ ]
    def add_title_label_to_browser ( self , title_text ) :
        pass
    def add_table_to_browser ( self ) :
        pass
    def add_return_button_to_browser ( self ) :
        pass
    def add_action_button_to_browser ( self , action_text ) :
        pass
    def add_title_row_to_browser ( self , number , name , creation_time , modification_time , size ) :
        pass
    def add_existing_row_to_browser ( self , number , name , creation_time , modification_time , size ) :
        pass
    def add_empty_row_to_browser ( self ) :
        pass
    def add_action_row_to_browser ( self ) :
        pass
    def set_entry_text_in_browser ( self , text ) :
        self . _entry_text = text
    def entry_text_in_browser_request ( self ) :
        self . _browser_logic . entry_text_in_browser_reply ( self . _entry_text ) 
    def focus_entry_in_browser ( self ) :
        pass
    def unfocus_entry_in_browser ( self ) :
        pass
    def select_table_row ( self , row ) :
        pass
    def unselect_table_row ( self , row ) :
        pass
    def localization_browser_number ( self ) :
        pass
    def localization_browser_existing_name ( self ) :
        pass
    def localization_browser_creation_time ( self ) :
        pass
    def localization_browser_modification_time ( self ) :
        pass
    def localization_browser_size ( self ) :
        pass
    def fetch_all_knowledge_bases ( self ) :
        self . _knowledge_bases_fetched = True
        for kb in self . _all_knowledge_bases :
            self . _knowledge_base_receiving_callback ( * kb )
    def rename_knowledge_base ( self , name , new_name ) :
        self . _call_history += [ mediator_fake . rename_knowledge_base ]
        self . _renamed_bases += [ [ name , new_name ] ]
    def show_browser ( self ) :
        self . _call_history += [ mediator_fake . show_browser ]
    def hide_browser ( self ) :
        self . _call_history += [ mediator_fake . hide_browser ]
    def bold_table_row ( self , row ) :
        pass
    
class browser_logic_rename_base_in_browser_tests :
    'browser_logic_rename_base_in_browser'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _browser_logic = browser_logic ( self . _mediator )
        self . _mediator . _browser_logic = self . _browser_logic
    def test_rename_base_in_browser_rename_knowledgebase ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'my name' , None , 'my time' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = 'my new name'
        self . _browser_logic . rename_base_in_browser ( )
        self . _test . assume_equal ( self . _mediator . _renamed_bases , [ [ 'my name' , 'my new name' ] ] )
    def test_rename_base_in_browser_no_bases ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = [ ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = 'my new name'
        self . _browser_logic . rename_base_in_browser ( )
        self . _test . assume_equal ( self . _mediator . _renamed_bases , [ ] )
    def test_rename_base_refresh_browser ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'my name' , None , 'my time' , None ]
            ]
        self . _browser_logic . configure_title_text_for_browser ( 'my title' )
        self . _browser_logic . configure_action_text_for_browser ( 'my action' )
        self . _browser_logic . configure_action_title_name_text_for_browser ( 'my action title' )
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = 'my new name'
        self . _browser_logic . rename_base_in_browser ( )
        self . _test . assume_equal ( self . _mediator . _call_history [ - 1 ] , mediator_fake . show_browser )
        self . _test . assume_equal ( self . _mediator . _call_history [ - 2 ] , mediator_fake . hide_browser )
    def test_rename_base_in_browser_rename_only_edited_knowledgebase ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'my name1' , None , 'my time1' , None ]
            , [ 'my name2' , None , 'my time2' , None ]
            , [ 'my name3' , None , 'my time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _browser_logic . on_key_up ( )
        self . _mediator . _entry_text = 'my new name'
        self . _browser_logic . rename_base_in_browser ( )
        self . _test . assume_equal ( self . _mediator . _renamed_bases , [ [ 'my name3' , 'my new name' ] ] )
